# -*- coding:utf-8 -*-

from httpbasic import getmgr
from Models import *
import json 

__username = None
__type = None

def getSheetList(username, type = 1):
	if username == None:
		return
	if type == None:
		return 
	
	global __username, __type
	__username = username
	__type = type
	jsonStr = __getSheetRawFile()
	l = []
	for row in json.loads(jsonStr, encoding="gbk"):
		str = json.dumps(row)
		sheet = json.loads(str, encoding="gbk", object_hook=dict2Sheet)
		sheet.username = username
		l.append(sheet)
	return l
	
	
	
def __getSheetRawFile():
	global __username, __type
	global __type
	with getmgr('10.97.87.200', '/eoms/portalQuery/queryWorkItem?userCode=%s&pageNum=1&listType=%s&callback=callback' % (__username,__type), 9084) as response:
		responseStr = response.read()
		return responseStr.replace('callback(','').replace(')','')

		
